package com.arrogames.blondbattle.game.combat 
{
	import ash.tools.ListIteratingSystem;
	import com.arrogames.blondbattle.game.graphics.BaseView;
	import com.arrogames.blondbattle.game.rendering.Display;
	import com.arrogames.blondbattle.game.movement.Position;
	import com.arrogames.blondbattle.game.purchases.Reward;
	import com.arrogames.blondbattle.game.EntityCreator;
	import com.arrogames.blondbattle.game.combat.DeathNode;
	import org.as3commons.logging.api.getLogger;
	import org.as3commons.logging.api.ILogger;
	
	
	/**
	 * ...
	 * @author Arnoud van Steenwijk
	 */
	public class DeathSystem extends ListIteratingSystem 
	{
		
		private static const logger:ILogger = getLogger(MissileSystem);
	
		private var entityCreator:EntityCreator = null;
		
		public function DeathSystem(pEntityCreator:EntityCreator)
		{
			entityCreator = pEntityCreator;
			super(DeathNode, updateNode);
		}

		public function updateNode(node:DeathNode, time:Number) : void {
			if ( node.health.value <= 0 ) {
				logger.debug("target " + node.entity.name + " got destroyed");
				var position:Position = node.position;
				var display:Display = node.display;
				var entityHeight:Number = display.displayObject.height;
				entityCreator.destroyEntity(node.entity);
				position.position.y -= entityHeight / 2;
				entityCreator.createExplosion(position, display.displayObject is BaseView);
				var reward:Reward = node.reward;
				entityCreator.createHitIndator(position, "PLUS  " + reward.value);
			}
		}
		
	}

	
}